package CreationPattern.Builder;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname : Phone
 * @Description : 产品类
 * @Author : chentianyu
 * @Date 2023/1/22 22:48
 */

// 手机抽象类
public abstract class AbstractPhone {

    private List<String> sequence = new ArrayList<>();

    /**
     * 基本方法
     */
    protected abstract void runAppA();
    protected abstract void runAppB();
    protected abstract void runAppC();

    // 钩子方法
    public final void setSequence(List<String> sequence) {
        this.sequence = sequence;
    }

    /**
     * 模板方法
     */
    public void run() {
        System.out.println();
        System.out.println("--手机运行开始---------------------------------------");
        for (String appName : sequence) {
            if (appName.equalsIgnoreCase("A")) this.runAppA();
            else if (appName.equalsIgnoreCase("B")) this.runAppB();
            else if (appName.equalsIgnoreCase("C")) this.runAppC();
        }
        System.out.println("--手机运行结束----------------------------------------");
    }
}


// 华为手机具体类
class HUAWEI extends AbstractPhone{

    @Override
    protected void runAppA() {
        System.out.println("华为手机运行应用A");
    }

    @Override
    protected void runAppB() {
        System.out.println("华为手机运行应用B");
    }

    @Override
    protected void runAppC() {
        System.out.println("华为手机运行应用C");
    }
}


// 小米手机具体类
class XIAOMI extends AbstractPhone {

    @Override
    protected void runAppA() {
        System.out.println("小米手机运行应用A");
    }

    @Override
    protected void runAppB() {
        System.out.println("小米手机运行应用B");
    }

    @Override
    protected void runAppC() {
        System.out.println("小米手机运行应用C");
    }
}
